﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Common;

public partial class _controls_navigation : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    { 
        if (Utils.IsNumber(RequestBase.GetQueryString("c_number")))
            NavBar = "<span class=\"current\">" + BLL.CommonBLL.ExecuteScalar("vw_ProductCategoryBase", "CategoryName", " AND CategoryNumber = '" + RequestBase.GetQueryString("c_number") + "' AND DeletionStateCode = 0").ToString() + "</span>";
        else
            NavBar = "<span class=\"current\">产品</span>";
    }
    public string NavBar = "";

    #region Navigation 导航
    void NavigationBar()
    {
        DataTable dt = BLL.CommonBLL.Select("vw_ProductCategoryBase", "*", " AND DeletionStateCode = 0 ORDER BY LineNum ASC");

        if (dt != null && dt.Rows.Count > 0)
        {
            BuildNavigationStr(dt, RequestBase.GetQueryString("c_number"));
            BuildNavigationBar(NavBar);
        }
        dt.Dispose();

    }
    /// <summary>
    /// 拼接当前类别目录字符串
    /// </summary>
    /// <param name="kindDS">数据集</param>
    /// <param name="kindCode">类别编码</param>
    void BuildNavigationStr(DataTable dt, string strCategoryNumber)
    {
        if (strCategoryNumber == "")
            return;

        DataRow[] dr = dt.Select("[CategoryNumber] = '" + strCategoryNumber + "'");

        if (dr != null && dr.Length > 0)
        {
            switch (dr[0]["Layer"].ToString())
            {
                case "1":
                    if (strCategoryNumber == RequestBase.GetQueryString("c_number"))
                        NavBar += "<span class=\"current\">" + dr[0]["CategoryName"].ToString().Trim() + "</span>";
                    else
                        NavBar += "<span><a href=\"productcatalog.aspx?c_number=" + dr[0]["CategoryNumber"].ToString().Trim() + "\">" + dr[0]["CategoryName"].ToString().Trim() + "</a></span>";
                    break;
                default:
                    if (strCategoryNumber == RequestBase.GetQueryString("c_number"))
                        NavBar += "<span class=\"current\">" + dr[0]["CategoryName"].ToString().Trim() + "</span>";
                    else
                        NavBar += "<span><a href=\"productlist.aspx?c_number=" + dr[0]["CategoryNumber"].ToString().Trim() + "\">" + dr[0]["CategoryName"].ToString().Trim() + "</a></span>";
                    break;
            }

            if (dr[0]["Layer"].ToString() == "1" || string.IsNullOrEmpty(dr[0]["ParentNumber"].ToString()))
                return;

            NavBar += "|";
            BuildNavigationStr(dt, dr[0]["ParentNumber"].ToString().Trim());
        }
        else
            return;
    }
    /// <summary>
    /// 合并当前类别目录字符串
    /// </summary>
    /// <param name="menuStr">当前位置目录字符串</param>
    void BuildNavigationBar(string _navBar)
    {
        string[] arryNav = _navBar.Split('|');
        NavBar = "";
        for (int i = arryNav.Length; i > 0; i--)
        {
            if (arryNav[i - 1] != "")
            {
                NavBar += "<span>&gt;&gt; </span>" + arryNav[i - 1];
            }
        }
        if (NavBar == "")
            NavBar = "<span class=\"current\">产品</span>";
        else
            NavBar = "<span><a href=\"productcatalog.aspx\">产品</a></span>" + NavBar;

    }
    #endregion
}
